<?php
class Admin_Form_TripCreateMultiple extends TBB_Form
{
	public function init()
	{
		// set attributes for main form
		$this->addAttribs(array(
			'class' => 'span-14',
			//'style' => 'background-color: #ccc;'
		));
		
		$fromCreateMultiple = $this->_createFromCreateMultiple();
		
		// create trip count element
		$tripCount = $this->_createTripCountElement();
		
		// create day count element
		$dayCount = $this->_createDayCountElement();
		
		// create starting date element
		$startDate = $this->_createStartDate();

		// create submit button
		$submit = $this->_createSubmitButton();
	
		$this->addElements(array($fromCreateMultiple, $tripCount, $dayCount, $startDate, $submit));
		$this->addDisplayGroup(array('tripCount', 'dayCount', 'startDate', 'submit'),
							  'createMultipleGroup',
							  array('class' => 'fieldsetForm span-7')
		);
		
		// set decorators for form
		$this->setDecorators($this->_formDecorators);
		$this->setDisplayGroupDecorators($this->_displayGroupDecorators);
	}
	
	private function _createStartDate()
	{
		$date = new ZendX_JQuery_Form_Element_DatePicker(
			'startDate',
			array(
				'JQueryParams' => array(
										'dateFormat' => 'dd-mm-yy',
										'defaultDate' => time())
			)
		);
		$date->setLabel('Ngày bắt đầu chạy: ');		
		// get current date		
		$date->setValue(TBB_Utility_Date::formatDate(TBB_Utility_Date::getCurrentDate()));	
		$date->setAttribs(array(
			'class' => 'span-6',
		));
		$date->getDecorator('Label')->setOption('class', 'span-4 labelDecorator');		
		return $date;
	}
	
	private function _createFromCreateMultiple()
	{
		$fromCreateMultiple = $this->createElement ( 'hidden', 'fromCreateMultiple' )
								  ->setDecorators ( $this->_hiddenDecorators )
								  ->setValue(1);
		$fromCreateMultiple->setAttribs(array(
			'class' => 'span-4',
		));
		return $fromCreateMultiple;
	}
	
	private function _createSubmitButton()
	{
		$submit = $this->createElement ( 'submit', 'submit' );
		$submit->setLabel ( 'Chấp nhận' );
		$submit->setDecorators($this->_submitDecorators);
		$submit->getDecorator('HtmlTag')->setOption('id', 'createTripButton');
		$submit->setAttribs(array(
			'class' => 'span-4 last submitDecorator',
		));
		return $submit;
	}
	
	private function _createDayCountElement() 
	{
		for($i = 1; $i <= 60; ++$i) {
			$options[$i] = (string)$i; 
		}
		$dayCount = $this->createElement('select', 'dayCount')
					 	 ->setLabel('Số ngày hoạt động: ')
					 	 ->setValue(3)
			 		 	 ->setMultiOptions($options);			 		 
		$dayCount->setAttribs(array(
			'class' => 'span-6'
		));
		$dayCount->getDecorator('Label')->setOption('class', 'span-4 labelDecorator');
		$dayCount->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $dayCount;
	}
	
	private function _createTripCountElement()
	{			
		for($i = 1; $i <= 5; ++$i) {
			$options[$i] = (string)$i; 
		}
		$tripCount = $this->createElement('select', 'tripCount')
					 ->setLabel('Số chuyến trong một ngày: ')
			 		 ->setMultiOptions($options)
			 		 ->setValue(2); 
		$tripCount->setAttribs(array(
			'class' => 'span-6'
		));
		$tripCount->getDecorator('Label')->setOption('class', 'span-4 labelDecorator');
		$tripCount->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		return $tripCount;
	}
	
	public function addRouteElement($routes = array())
	{
		$route = $this->createElement('select', 'route')
					   ->setLabel('Tuyến: ')
			 		   ->setMultiOptions($routes)
			 		   ->setOrder(0);
		$route->setAttribs(array(
			'class' => 'span-6'
		));
		$route->getDecorator('Label')->setOption('class', 'span-4 labelDecorator');
		$route->getDecorator('Errors')->setOption('class', 'span-6 errorDecorator');
		
		// add route element to display group
		$this->getDisplayGroup('createMultipleGroup')->addElement($route);	
	}
}